package ObjGitRequest

import (
	"arabApi/app/api/requests"
	"github.com/gin-gonic/gin"
	"github.com/thedevsaddam/govalidator"
)

type GitPushPathRequest struct {
	ID    int64  `json:"id"`
	JobId int64  `gorm:"column:job_id" db:"job_id" json:"job_id"` //  项目id
	Step  int64  `gorm:"column:step" db:"step" json:"step"`       //   2 测试环境 3 开发环境 4 正式环境
	Ip    string `gorm:"column:ip" db:"ip" json:"ip"`             //  发布ip
	Path  string `gorm:"column:path" db:"path" json:"path"`       //  项目存放地址
	Desc  string `gorm:"column:desc" db:"desc" json:"desc"`       //  描述
}

func CheckGitPushPath(data interface{}, c *gin.Context) string {
	// 自定义验证规则
	rules := govalidator.MapData{
		"job_id": []string{"required"},
		"step":   []string{"required"},
		"ip":     []string{"required"},
		"path":   []string{"required"},
		"desc":   []string{"required"},
	}
	// 自定义验证出错时的提示
	messages := govalidator.MapData{
		"job_id": []string{
			"required:项目不能为空",
		},
		"step": []string{
			"required:step 不能为空",
		},
		"ip": []string{
			"required:ip 不能为空",
		},
		"path": []string{
			"required:路径不能为空",
		},
		"desc": []string{
			"required:描述不能为空",
		},
	}

	errs := requests.Validate1(data, rules, messages)
	return requests.GetOneErr(errs)
}
